package cn.wolfcode.education.web.controller;

import cn.wolfcode.education.anno.PermissionName;
import cn.wolfcode.education.domain.LossStu;
import cn.wolfcode.education.query.LossStuQuery;
import cn.wolfcode.education.service.ILossStuService;
import cn.wolfcode.education.util.JSONResult;
import cn.wolfcode.education.util.PageResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("lossStu")
public class LossStuController {
    @Autowired
    private ILossStuService lossStuService;

    @RequestMapping("")
    @PermissionName("学员退学管理")
    @RequiresPermissions("lossStu:view")
    public String index(){
        return "lossStu/lossStu";
    }

    @RequestMapping("query")
    @ResponseBody
    @PermissionName("学员退学列表")
    @RequiresPermissions("lossStu:query")
    public PageResult query(LossStuQuery qo){
        return lossStuService.query(qo);
    }

    @RequestMapping("update")
    @ResponseBody
    @PermissionName("学员退学更新")
    @RequiresPermissions("lossStu:update")
    public JSONResult update(LossStu lossStu){
        JSONResult jsonResult = new JSONResult();
        try {
            lossStuService.update(lossStu);
        }catch (Exception e){
            jsonResult.setMsg("更新失败");
        }
        return jsonResult;
    }

    @RequestMapping("auditLossStu")
    @ResponseBody
    @PermissionName("学员退学审核")
    @RequiresPermissions("lossStu:auditLossStu")
    public JSONResult auditLossStu(Long id){
        JSONResult jsonResult = new JSONResult();
        try {
            lossStuService.auditLossStu(id);
        }catch (Exception e){
            jsonResult.setMsg("审核失败");
        }
        return jsonResult;
    }

    @RequestMapping("unauditLossStu")
    @ResponseBody
    @PermissionName("学员退学反审核")
    @RequiresPermissions("lossStu:unauditLossStu")
    public JSONResult unauditLossStu(Long id){
        JSONResult jsonResult = new JSONResult();
        try {
            lossStuService.unauditLossStu(id);
        }catch (Exception e){
            jsonResult.setMsg("反审核失败");
        }
        return jsonResult;
    }
}
